package com.open.party.cloud.view.examine.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.open.party.cloud.R;
import com.open.party.cloud.model.CourseTeacherEntity;
import com.sinothk.android.utils.XUtils;
import com.sinothk.android.utils.inters.OnSuperListener;

import java.util.ArrayList;
import java.util.List;

public class ExamineClassTeacherListAdapter extends RecyclerView.Adapter<ExamineClassTeacherListAdapter.ViewHolder> {

    // 展示数据
    protected ArrayList<CourseTeacherEntity> mData;
    private Context mContext;
    private OnSuperListener<CourseTeacherEntity> onSuperListener;

    public ExamineClassTeacherListAdapter(Context mContext) {
        this.mContext = mContext;
        this.mData = new ArrayList<>();
    }

    public void setOnSuperListener(OnSuperListener<CourseTeacherEntity> onSuperListener) {
        this.onSuperListener = onSuperListener;
    }

    public void setData(List<CourseTeacherEntity> data) {
        if (mData == null) {
            mData = new ArrayList<>();
        } else {
            mData.clear();
        }
        if (data == null) {
            data = new ArrayList<>();
        }
        this.mData.addAll(data);
        notifyDataSetChanged();
    }

    public void updateData(List<CourseTeacherEntity> data) {
        this.mData.addAll(data);
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return mData == null ? 0 : mData.size();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.examine_class_teacher_list_item, viewGroup, false);
        return new ViewHolder(view);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        // 绑定数据
        final CourseTeacherEntity itemData = mData.get(position);

        holder.courseNameTv.setText(XUtils.string().getNotNullValue(itemData.getCourseName()));
//        holder.titleTv.setText("教师姓名：" + XUtils.string().getNotNullValue(itemData.getUserName()));
//        holder.userPhoneTv.setText("教师电话：" + XUtils.string().getNotNullValue(itemData.getTechPhone()));

        holder.startTimeTv.setText("开始时间：" + XUtils.string().getNotNullValue(itemData.getStartTime()));
        holder.endTimeTv.setText("结束时间：" + XUtils.string().getNotNullValue(itemData.getEndTime()));

//        if ("M".equals(itemData.getSex())) {
//            holder.sexTv.setText("教师性别：男");
//        } else {
//            holder.sexTv.setText("教师性别：女");
//        }

        if (mData.size() - 1 == position) {
            holder.bottomLineTv.setVisibility(View.VISIBLE);
        } else {
            holder.bottomLineTv.setVisibility(View.GONE);
        }

        if (itemData.isEval()) {
            holder.evalBtn.setText("已评价");
            holder.evalBtn.setBackgroundResource(R.drawable.selector_green_square_round_r6);
        } else {
            holder.evalBtn.setText("未评价");
            holder.evalBtn.setBackgroundResource(R.drawable.selector_red_square_round_r6);
        }

        if (onSuperListener != null) {
            holder.rootView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onSuperListener.onClick(position, itemData, "rootView");
                }
            });
        }
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout rootView;
        TextView bottomLineTv, evalBtn, courseNameTv, startTimeTv, endTimeTv; //titleTv, sexTv, userPhoneTv,

        ViewHolder(View itemView) {
            super(itemView);
            rootView = itemView.findViewById(R.id.rootView);

            courseNameTv = itemView.findViewById(R.id.courseNameTv);
//            titleTv = itemView.findViewById(R.id.titleTv);
//            sexTv = itemView.findViewById(R.id.sexTv);
//            userPhoneTv = itemView.findViewById(R.id.userPhoneTv);
            evalBtn = itemView.findViewById(R.id.evalBtn);

            bottomLineTv = itemView.findViewById(R.id.bottomLineTv);

            startTimeTv = itemView.findViewById(R.id.startTimeTv);
            endTimeTv = itemView.findViewById(R.id.endTimeTv);
        }
    }
}